package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by siba on 27/09/14.
 */
public class User {
    private String libraryNumber;
    private String password;
    private String name;
    private String email;
    private String phoneNumber;
    private List booksCheckedOut = new ArrayList();

    public void setLibraryNumber(String libraryNumber){
        this.libraryNumber = libraryNumber;
    }
    public void setPassword(String password){
        this.password = password;
    }
    public void setName(String name){
        this.name = name;
    }
    public void setEmail(String email){
        this.email = email;
    }
    public void setPhoneNumber (String phoneNumber){
        this.phoneNumber = phoneNumber;
    }
    public void setBooksCheckedOut(List booksCheckedOut){
        this.booksCheckedOut = booksCheckedOut;
    }

    public String getLibraryNumber(){
        return libraryNumber;
    }
    public String getPassword(){
        return password;
    }
    public String getName(){
        return name;
    }
    public String getEmail(){
        return email;
    }
    public String getPhoneNumber(){
        return phoneNumber;
    }
    public List getBooksCheckedOut(){
        return booksCheckedOut;
    }

    public void addToBooksCheckedOut(Book book){
        booksCheckedOut.add(book);
    }

    public void removeFromBooksCheckedOut(Book book){
        for(int count = 0; count < booksCheckedOut.size(); count++){
            if(((Book) booksCheckedOut.get(count)).getTitle().equalsIgnoreCase(book.getTitle()) &&
                    ((Book) booksCheckedOut.get(count)).getAuthor().equalsIgnoreCase(book.getAuthor()) &&
                    ((Book) booksCheckedOut.get(count)).getYearPublished().equalsIgnoreCase(book.getYearPublished())){
                booksCheckedOut.remove(count);
            }

        }
    }

    public static User findUser (String [] userCredentials){
        for(User user: new UserInformation().getUsers()){
            if (userCredentials[0].equalsIgnoreCase(user.getLibraryNumber()) &&
                    userCredentials[1].equals(user.getPassword())){
                return user;
            }
        }
        return null;
    }

    public void displayUserInfo() {
        new BibliotecaMessages(System.out).printMessage("\nName: " + getName() + "\nE-mail: " + getEmail() +
                "\nPhone number: " + getPhoneNumber());

        for(int count = 0; count < booksCheckedOut.size(); count++){
            new BibliotecaMessages(System.out).printMessage(((Book) booksCheckedOut.get(count)).getTitle());        }

    }
}
